
import sys
from PyQt5.QtWidgets import (QApplication, QMainWindow, QPushButton, QLabel, 
                             QVBoxLayout, QHBoxLayout, QAction, QMenuBar, 
                             QToolBar, QMessageBox, QWidget)
from PyQt5.QtCore import QTimer, QTime, Qt, QSize
from PyQt5.QtGui import QFont, QIcon, QPixmap


# 创建主窗口类
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()
        
    def initUI(self):
        # 设置窗口标题和大小
        self.setWindowTitle("PyQt5 动态时钟示例界面")
        self.resize(500, 300)
        
        # 创建中心部件
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        
        # 创建菜单栏
        self.create_menu_bar()
        
        # 创建工具栏
        self.create_tool_bar()
        
        # 主垂直布局
        self.main_layout = QVBoxLayout()
        central_widget.setLayout(self.main_layout)
        
        # 时钟标签
        self.clock_label = QLabel()
        self.clock_label.setAlignment(Qt.AlignCenter)
        self.clock_label.setFont(QFont("Noto Sans CJK SC", 24))
        self.main_layout.addWidget(self.clock_label)
        
        # 普通标签和按钮水平布局
        self.row_layout = QHBoxLayout()
        self.label = QLabel("Hello, PyQt5!")
        self.label.setFont(QFont("Noto Sans CJK SC", 14))
        self.row_layout.addWidget(self.label)
        
        self.button = QPushButton("点击我")
        self.button.setFont(QFont("Noto Sans CJK SC", 12))
        self.button.clicked.connect(self.on_click)
        self.row_layout.addWidget(self.button)
        
        self.main_layout.addLayout(self.row_layout)
        
        # 时钟定时器逻辑
        self.timer = QTimer()
        self.timer.timeout.connect(self.update_clock)
        self.timer.start(1000)
        self.update_clock()
        
    def create_menu_bar(self):
        # 创建菜单栏
        menubar = self.menuBar()
        
        # 文件菜单
        file_menu = menubar.addMenu('文件')
        
        # 新建动作
        new_action = QAction('新建', self)
        new_action.setShortcut('Ctrl+N')
        new_action.triggered.connect(self.show_new_dialog)
        file_menu.addAction(new_action)
        
        # 保存动作
        save_action = QAction('保存', self)
        save_action.setShortcut('Ctrl+S')
        save_action.triggered.connect(self.show_save_dialog)
        file_menu.addAction(save_action)
        
        # 退出动作
        exit_action = QAction('退出', self)
        exit_action.setShortcut('Ctrl+Q')
        exit_action.triggered.connect(self.close)
        file_menu.addAction(exit_action)
        
        # 编辑菜单
        edit_menu = menubar.addMenu('编辑')
        
        # 剪切动作
        cut_action = QAction('剪切', self)
        cut_action.setShortcut('Ctrl+X')
        edit_menu.addAction(cut_action)
        
        # 复制动作
        copy_action = QAction('复制', self)
        copy_action.setShortcut('Ctrl+C')
        edit_menu.addAction(copy_action)
        
        # 粘贴动作
        paste_action = QAction('粘贴', self)
        paste_action.setShortcut('Ctrl+V')
        edit_menu.addAction(paste_action)
        
        # 帮助菜单
        help_menu = menubar.addMenu('帮助')
        
        # 关于动作
        about_action = QAction('关于', self)
        about_action.triggered.connect(self.show_about_dialog)
        help_menu.addAction(about_action)
        
    def create_tool_bar(self):
        # 创建工具栏
        toolbar = QToolBar("工具栏", self)
        self.addToolBar(toolbar)
        
        # 设置工具栏图标大小
        toolbar.setIconSize(QSize(24, 24))
        
        # 新建按钮
        new_action = QAction('新建', self)
        toolbar.addAction(new_action)
        
        # 保存按钮
        save_action = QAction('保存', self)
        toolbar.addAction(save_action)
        
        # 分隔符
        toolbar.addSeparator()
        
        # 剪切按钮
        cut_action = QAction('剪切', self)
        toolbar.addAction(cut_action)
        
        # 复制按钮
        copy_action = QAction('复制', self)
        toolbar.addAction(copy_action)
        
        # 粘贴按钮
        paste_action = QAction('粘贴', self)
        toolbar.addAction(paste_action)
        
    def on_click(self):
        self.label.setText("按钮被点击了！")
        
    def update_clock(self):
        current_time = QTime.currentTime().toString("HH:mm:ss")
        self.clock_label.setText(current_time)
        
    def show_new_dialog(self):
        QMessageBox.information(self, "新建", "新建功能尚未实现")
        
    def show_save_dialog(self):
        QMessageBox.information(self, "保存", "保存功能尚未实现")
        
    def show_about_dialog(self):
        QMessageBox.about(self, "关于", "PyQt5 示例程序\n版本 1.0\n一个简单的PyQt5界面示例")


app = QApplication(sys.argv)

# 创建并显示主窗口
window = MainWindow()
window.show()

sys.exit(app.exec_())
